import cv2

# Capture a video using a webcam
cam = cv2.VideoCapture(0)

# Read a file
# cam = cv2.VideoCapture('videos/video.avi')
# if not cam.isOpened():
#     print(f"Open error")
#     exit()

# Set the start point to frame 100
# start_frame = 100
# total_frames = int(cam.get(cv2.CAP_PROP_FRAME_COUNT))
# print(f"Total frames in video: {total_frames}")
# if start_frame >= total_frames:
#     print("Error: Start frame exceeds total frames in video.")
#     cam.release()
#     exit()
# cam.set(cv2.CAP_PROP_POS_FRAMES, start_frame)

while cam.isOpened():
    ret, frame = cam.read()
    if not ret or frame is None:
        print("Failed to read frame.")
        break

    cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xFF == ord('Q'):
        break

cam.release()
cv2.destroyAllWindows()
